package com.deliveryservicesystem.presentation.desktop;

import com.jgoodies.validation.view.ValidationComponentUtils;
import java.awt.Component;
import java.awt.KeyboardFocusManager;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JComponent;
import javax.swing.JLabel;

/**
 * File Name: InfoLableChangeHandler.java
 * Version:
 * Description:
 * Package: com.deliveryservicesystem.presentation.desktop
 * Author: Lance
 * Date: Jun 24, 2012
 * Editor:
 */
public class InfoLableChangeHandler implements PropertyChangeListener
{

    private JLabel infoLabel;

    public InfoLableChangeHandler(JLabel infoLabel)
    {
        this.infoLabel = infoLabel;
    }

    @Override
    public void propertyChange(PropertyChangeEvent evt)
    {
        String propertyName = evt.getPropertyName();
        if (!"permanentFocusOwner".equals(propertyName))
        {
            return;
        }

        Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();

        String focusHint = (focusOwner instanceof JComponent)
                ? (String) ValidationComponentUtils.getInputHint((JComponent) focusOwner)
                : null;

        infoLabel.setText(focusHint);
        infoLabel.setVisible(true);
    }
}
